package com.Renting.service.impl;
import com.Renting.dao.GainDao;
import com.Renting.dao.RentingDao;
import com.Renting.domain.Renting;
import com.Renting.domain.RentingUser;
import com.Renting.domain.record;
import com.Renting.service.ServiceGain;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Iterator;
import java.util.List;


@Service
public class ServiceGainImpl implements ServiceGain{

    @Resource
    GainDao gainDao;
    @Resource
    RentingDao rentingDao;

    //进入首页时显示所有未出租的房间
    @Override
    public void getRunting(HttpSession session) {
        List<Renting> ListRenting= gainDao.getRuntingDao();
        session.setAttribute("ListRenting",ListRenting);
    }

    //查看指定的房间类型
    @Override
    public void ServiceRentingInquire(Renting renting,HttpSession session) {
        List<Renting> ListRenting= gainDao.RentingInquireDao(renting);
        session.setAttribute("ListRentingInquire",ListRenting);
    }

    //查看自己预约的房间
    @Override
    public void MyRentingService(HttpSession session) {
        RentingUser user= (RentingUser) session.getAttribute("Message");
        List<Renting> ListResult= gainDao.MyRentingDao(user);
        session.setAttribute("ListRentingInquire",ListResult);
    }

    //查看自己入住的房间
    @Override
    public void MyRoomService(HttpSession session) {
       RentingUser user= (RentingUser) session.getAttribute("Message");
        List<Renting> ListResult=  gainDao.GetMyRoom(user);
        session.setAttribute("ListRentingInquire",ListResult);
    }

    //每次管理员对数据进行操作后，为了让页面响应，需要更新session内的数据
    @Override
    public void GetRoomUser(HttpSession session) {
        List<Renting> listroom= gainDao.GetRoom();
        List<RentingUser> listuser= gainDao.GetUser();
        List<record> listrecord= gainDao.GetRecord();
        session.setAttribute("listroom",listroom);
        session.setAttribute("listuser",listuser);
        session.setAttribute("listrecord",listrecord);
    }

    //如果登录的用户被抢房，则执行该程序提醒用户预定的房间发生了变化
    @Override
    public void GetHint(HttpSession session) {
        RentingUser user=(RentingUser) session.getAttribute("Message");
        RentingUser result=gainDao.GetHint(user);
        if(result.getPalter()==1){
            session.setAttribute("hint","您预定的房间发生了变化!");
            user.setPalter(0);
            rentingDao.RentingHint(user);
        }
    }

    //查询房间
    @Override
    public void GetRenting(Renting renting, HttpSession session) {
       List<Renting> ren= gainDao.GetRenting(renting);
       session.setAttribute("queryroom",ren);
    }

    //查询用户
    @Override
    public void GetUser(RentingUser user,HttpSession session) {
        List<RentingUser> list=gainDao.GetQueryUser(user);
        session.setAttribute("queryuser",list);
    }
}